package com.pucheng.bracelet.viewmodel.steps

import androidx.lifecycle.*
import com.pucheng.bracelet.app.database.repository.DBRepository
import com.pucheng.bracelet.app.util.CacheUtil
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import com.pucheng.bracelet.app.util.DatetimeUtil
import com.pucheng.bracelet.data.bean.StepsBean
import me.hgj.jetpackmvvm.ext.launch

class StepsToDayViewModel : BaseViewModel() {

    private val repository: DBRepository = DBRepository()
    public var queryDate = MutableLiveData<String>().apply {
        value = DatetimeUtil.getNowDate(DatetimeUtil.DATE_PATTERN)
    }

    var stepsData = MutableLiveData<StepsBean>()
    var stepsTager =MutableLiveData<String>().apply {
        value = CacheUtil.getStepsFlag()
    }

    fun queryDateToDate(){

        launch({
            repository.getStepsInfoToDate2(queryDate.value!!)
        },{
            if (it != null) {
                stepsData.value = it
            }else{
                stepsData.value = StepsBean()
            }
        },{})
    }
}

